#ifndef CPROPERTYEDITOR_H
#define CPROPERTYEDITOR_H

#include <QTableWidget>
#include <vector>
#include "CPropertyEditorItem.h"
#include "CPropertyItem.h"
#include "CGroupItem.h"

//-------------------------------------

struct LessGroupItem : public std::binary_function< CGroupItem*, CGroupItem*, bool >
{
    bool operator()( const CGroupItem* arg1, const CGroupItem* arg2 ) const
    {
        return arg1->GetName() > arg2->GetName();
    }
};

//-------------------------------------

class CPropertyEditor : public QTableWidget
{
    Q_OBJECT

    std::vector< CPropertyEditorItem* > items;

    std::set< CGroupItem*, LessGroupItem > groups;
    std::set< CPropertyItem*, LessPropItem > props;
    friend class CPropertyItem;



public:
    explicit CPropertyEditor( QWidget *parent = 0 );

    CPropertyItem * CreateProperty( const QString & group, const QString & key, const QString & value );
    void AddProperty( const QString & group, CPropertyItem * property );
    void DeleteProperty( const QString & group, const QString & key );
    CPropertyItem * GetProperty( const QString & group, const QString & key );
    CPropertyItem * GetProperty( const QString & str );
    CGroupItem * GetGroup( const QString & str );

    virtual void Update ();

    CGroupItem* GetGroupOrCreate( const QString & str );
    CGroupItem* CreateGroup( const QString & str );

    void Clear();

    bool updateInProgress;

    void BeginUpdate() { updateInProgress = true; }
    void EndUpdate() { updateInProgress = false; Update(); }

protected:
    void AddPropRef( CPropertyItem * p );
    void RemovePropRef( CPropertyItem * p );
    void FillTable();
    
signals:
    
public slots:

    
};

#endif // CPROPERTYEDITOR_H
